home *** CD-ROM | disk | FTP | other *** search
- /* Metrowerks Standard Library Version 2.1.2b7 1997 May */
-
- /*
- * File: utime.c
- * ©1993-1996 metrowerks Inc. All rights reserved
- * Author: Berardino E. Baratta
- *
- * Content: Interface file to standard UNIX-style entry points ...
- *
- * NB: This file implements some UNIX low level support. These functions
- * are not guaranteed to be 100% conformant.
- *
- */
-
- #include <utime.h>
-
- #include <errno.h>
-
- #include <Files.h>
- #include <LowMem.h>
- #include <Types.h>
- #include <time.mac.h> /*mm970521 */
-
- /* function prototypes for externally defined functions */
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- extern int __ctopstring(const char *cstring, Str255 pstring);
-
- #ifdef __cplusplus
- }
- #endif
-
- /*
- * Set the file time stamps.
- */
- static int __settime(Str255 ppath, unsigned long modtime)
- {
- HFileInfo pb;
- short vrefnum = 0;
- long dirid = 0L;
- OSErr err = noErr;
-
- pb.ioNamePtr = ppath;
- pb.ioVRefNum = vrefnum;
- pb.ioDirID = dirid;
- pb.ioFVersNum = 0;
- pb.ioFDirIndex = 0;
-
- err = PBHGetFInfoSync((HParmBlkPtr)&pb);
- if (err == noErr) {
- pb.ioNamePtr = ppath;
- pb.ioVRefNum = vrefnum;
- pb.ioDirID = dirid;
- pb.ioFVersNum = 0;
- pb.ioFDirIndex = 0;
- pb.ioFlMdDat = modtime;
-
- err = PBHSetFInfoSync((HParmBlkPtr)&pb);
- }
-
- if (err != noErr)
- errno = err;
- return (err == noErr ? 0 : -1);
- }
-
- /*
- * Set the file time stamps.
- */
- int utime(const char *path, const struct utimbuf *buf)
- {
- Str255 ppath;
- unsigned long modtime = NULL;
-
- if (path) {
- /* convert the C string into a Pascal string */
- if (__ctopstring(path, ppath) != noErr) return (-1);
-
- if (buf != NULL && buf->modtime != NULL)
- modtime = buf->modtime; /* we ignore the access time on the Mac */
-
- if (modtime == NULL)
- GetDateTime(&modtime); /* set it to the current time */
- else /* mm 970521*/
- modtime -= _mac_unix_epoch_offset_; /* mm 970521*/
-
- return (__settime(ppath, modtime));
- }
-
- return (-1);
- }
-
- /*
- * Set the file time stamps.
- */
- int utimes(const char *path, struct timeval buf[2])
- {
- Str255 ppath;
- unsigned long modtime;
-
- if (path) {
- /* convert the C string into a Pascal string */
- if (__ctopstring(path, ppath) != noErr) return (-1);
-
- modtime = buf[1].tv_sec;
-
- if (modtime == NULL)
- GetDateTime(&modtime); /* set it to the current time */
- else /* mm 970521*/
- modtime -= _mac_unix_epoch_offset_; /* mm 970521*/
-
- return (__settime(ppath, modtime));
- }
-
- return (-1);
- }
- /* Change Record
- * 30-Dec-95 JFH Removed uses of OLDROUTINENAMES
- * mm 970521 Added correction for difference in 1900Jan01 and 1904Jan01 epochs
- */
-